package com.visikard.response;

import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import com.visikard.item.ItemRedeemDetails;
import com.visikard.request.ParseRequesUtils;

public class GetDetailRedeemResponse extends BaseResponse {

	private int redeemCount;
	private String kardNumber;
	private String address;
	private String status;
	private String paymentMethod;
	private String redemptionCode;
	private List<ItemRedeemDetails> listItemRedeemDetails;

	public int getRedeemCount() {
		return redeemCount;
	}

	public void setRedeemCount(int redeemCount) {
		this.redeemCount = redeemCount;
	}

	public String getKardNumber() {
		return kardNumber;
	}

	public void setKardNumber(String kardNumber) {
		this.kardNumber = kardNumber;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getPaymentMethod() {
		return paymentMethod;
	}

	public void setPaymentMethod(String paymentMethod) {
		this.paymentMethod = paymentMethod;
	}

	public String getRedemptionCode() {
		return redemptionCode;
	}

	public void setRedemptionCode(String redemptionCode) {
		this.redemptionCode = redemptionCode;
	}

	public List<ItemRedeemDetails> getListItemRedeemDetails() {
		return listItemRedeemDetails;
	}

	public void setListItemRedeemDetails(List<ItemRedeemDetails> listItemRedeemDetails) {
		this.listItemRedeemDetails = listItemRedeemDetails;
	}

	@Override
	public void extractDataFromServer(String response) throws JSONException {
		super.extractDataFromServer(response);

		if (errorCode == SUCCESS) {
			JSONObject json = getDataJObject(response);

			if (json.has("redeemedCount"))
				redeemCount = json.optInt("redeemedCount", 0);

			if (json.has("kardNumber"))
				kardNumber = json.optString("kardNumber", "");

			if (json.has("address"))
				address = json.optString("address", "");

			if (json.has("status"))
				status = json.optString("status", "");

			if (json.has("otherRedeem")) {
				listItemRedeemDetails = ParseRequesUtils.parseTransactionHistoryDetails(json.optString("otherRedeem"));
			}

			if (json.has("paymentMethod"))
				paymentMethod = json.optString("paymentMethod", "");

			if (json.has("redeemptionCode"))
				redemptionCode = json.optString("redeemptionCode", "");
		}

	}

}
